package com.uxwine.alarm.main;

import java.util.TimerTask;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.LinearLayout;

import com.uxwine.alarm.R;
import com.uxwine.alarm.R.color;
import com.uxwine.view.SlideWindow;

public class NameWindow extends SlideWindow implements View.OnClickListener{

	private AlarmBuilder mAlarmBuilder;
	private EditText mEdit; 
	private LabelAdapter mNoteAdapter;
	private GridView mNotices;
	private LinearLayout mCtnMain;
	
	public NameWindow(Context ctx) {
		super(ctx);
		initView();
	}		
	
	public void show(View parent)
	{
		final Resources res = getContext().getResources();
		String[] data = res.getStringArray(R.array.alerm_notice);
		mNoteAdapter.update(data);
		mNotices.setAdapter(mNoteAdapter);
		
		if(null != mAlarmBuilder)
		{
			Alarm a = mAlarmBuilder.build().getAlarm();
			mEdit.setText(a.getName());
		}
		showAtLocation(parent, Gravity.TOP, 0, 0);
	}	
	
	public void setAlarmBuilder(AlarmBuilder builder)
	{
		mAlarmBuilder = builder;
	}
	
	private void initView()
	{
		final Context context = getContext();
		setContentView(R.layout.view_alarm_name);
		findViewById(R.id.alarm_name_ok).setOnClickListener(this);
		findViewById(R.id.alarm_name_cancel).setOnClickListener(this);
		mEdit = (EditText)findViewById(R.id.alarm_name_edit);
		mNotices = (GridView)findViewById(R.id.alarm_name_note);
		mCtnMain = (LinearLayout)findViewById(R.id.alarm_name_ctn);
		
		mNoteAdapter = new LabelAdapter(context);
		
		ColorDrawable cd = new ColorDrawable(-00000);
		setBackgroundDrawable(cd);
		
	}
	
	
	
	
	@Override
	public void onClick(View v) {
		int id = v.getId();
		if(id == R.id.alarm_name_ok)
		{
			if(mAlarmBuilder != null)
			{
				mAlarmBuilder.setName(mEdit.getText().toString());
				mAlarmBuilder.build().save();
			}
			exit(1);
		}
		else if(id == R.id.alarm_name_cancel)
		{
			exit(0);
		}
	}
}
